<?php extract ( $_GET );

	include 'wp-includes/php/DBManager.class.php';
	
	$db = new DBManager ( 'localhost', 'root', '', 'iumus' );
	
	$query = "SELECT rating, votes FROM movie WHERE id = '".$film."'";
	$result = $db->executeQuery ( $query );
	$infoFilm = mysql_fetch_array ( $result );
	
	$newVotes = $infoFilm[1] + 1;
	$newRating = ( ( $infoFilm[0] * $infoFilm[1] ) + $score ) / $newVotes;
	$newRating=round($newRating, 2);
	
	if ( isset ( $user ) && strlen ( $user ) > 0 && $user != "noSet" ) {
		$query = "UPDATE `iumus`.`movie` SET rating = $newRating, votes = $newVotes WHERE id = '".$film."'";
		$db->executeQuery ( $query );
		echo "Thanks for your vote!";
	} else echo "You must be logged to vote!";
?>